<template>
  <a-table :loading="loading" :dataSource="dataSource" :columns="columns" />
</template>
<script setup>
  import { ref, watch, defineProps,onMounted } from 'vue';
  import { classlist, deleteOne, batchDelete, getImportUrl, getExportUrl } from './BdMaterial.api';

  const dataSource = ref([]);
  const columns = ref([
    {
      title: '物料名称',
      key: 'name',
      dataIndex: 'name',
    },
    {
      title: '物料编码',
      key: 'code',
      dataIndex: 'code',
    },
    {
      title: '规格',
      key: 'materialspec',
      dataIndex: 'materialspec',
    },
    {
      title: '型号',
      key: 'materialtype',
      dataIndex: 'materialtype',
    },
    {
      title: '条形码',
      key: 'materialbarcode',
      dataIndex: 'materialbarcode',
    },
    {
      title: '物料分类',
      key: 'pkMarbasclass',
      dataIndex: 'pkMarbasclass',
    },
    {
      title: '启用状态',
      key: 'enablestate',
      dataIndex: 'enablestate',
    },
  ]);
  const loading = ref(false);
  const props = defineProps({
    curtype: {},
  });

  watch(
    () => props.curtype,
    (n) => {
      if(!n) return
      fetch(n);
    }
  );

  onMounted(()=>{
    fetch('');
  })

  async function fetch(n) {
    loading.value = true;
    const res = await classlist({
      id: n,
    });
    loading.value = false;

    dataSource.value = res.records;
  }
</script>
